﻿using System;
using System.ComponentModel;
using LockerRack.Helpers;
using LockerRack.Interfaces;
using Primitive.Mvvm.Framework.Implementations;
using Primitive.Mvvm.Framework.Interfaces;
using UIController.Models;

namespace DataController.ViewModels
{
    public class BottomViewModel : BaseViewModel
    {
        private ToDoModel _model;
        public BottomViewModel(IModel model, IMediator mediator) : base(mediator)
        {
            _model = model as ToDoModel;
        }

        public IDrawerFile SelectedFile
        {
            get { return _model.With(m => m.SelectedFile); }
        }

        public string TaskNote
        {
            get
            {
                if (SelectedFile == null)
                    return string.Empty;

                var bag = SelectedFile.With(f => f.Contents).Return(c => c.PropertyBag, null);

                if (PropertyExists(bag, "Note"))
                    return bag.Note;

                return string.Empty;
            }
            set
            {
                if (SelectedFile == null || SelectedFile.Contents == null)
                    return;

                if (PropertyExists(SelectedFile.Contents.PropertyBag, "Note"))
                {
                    SelectedFile.Contents.PropertyBag.Note = value;
                    RaisePropertyChanged(this, () => TaskNote);
                }
            }
        }
    }
}
